package com.bang.study.lock;

import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.xcontent.XContentFactory;


/**
 * @ClassName: LockUtil
 * @author: BANG
 * @Date: 2020/01/16 13:54
 * @Version: 1.0
 * @Modified By:
 * @Desc: TODO
 */
public class LockUtil {


    public static IndexResponse addGlobalLock(Client client) throws Exception {
        return client.prepareIndex("fs", "lock")
                .setId("global")
                .setCreate(true)
                .setSource(XContentFactory.jsonBuilder().startObject().endObject())
                .get();
    }

    public static DeleteResponse releaseGlobalLock(Client client) throws Exception {
      return client.prepareDelete("fs", "lock", "global").get();
    }
}
